package mop.model.task.field;

import mop.exception.IllegalDescriptionException;
import mop.exception.IllegalFieldTypeException;
import mop.exception.IllegalIdException;

/**
 * Field factory 
 * Creates fields on basis of type,id & description
 * @author MOP Team 7
 */
public class FieldFactory {
	
	/**
	 * Create a field
	 * 
	 * @param type			Type of field
	 * @param id			Field identifier
	 * @param description	Field description
	 * 
	 * @return	Field
	 * 
	 * @throws IllegalIdException
	 * 	| @see Field#setId()
	 * @throws IllegalDescriptionException
	 * 	| @see Field#setDescription()
	 * @throws IllegalFieldTypeException
	 * 	When field type does not exist
	 */
	public static Field createField(String type, String id, String description) throws IllegalIdException, IllegalDescriptionException, IllegalFieldTypeException{
		Field f;
		if(type.equals("textual")){
			f = new StringField(id,description);
		}else if(type.equals("numeric")){
			f = new IntField(id,description);
		}else{
			throw new IllegalFieldTypeException(type,id);
		}
		
		return f;
	}
}
